home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / What's New? / Software Development Kits / Mac OS USB DDK / MacOS USB DDK 1.0b4 / NeptuneDDK / Examples / SerialBox / serialboxShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-26  |  5.3 KB  |  206 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        serialboxShell.c
  3.  
  4.     Contains:    Wrapper for serial box driver
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12.  
  13. #include <Types.h>
  14. #include <Devices.h>
  15. #include <DriverServices.h>
  16. #include <USB.h>
  17. #include "ShimSerialInternal.h"
  18. #include "SerialBox.h"
  19.  
  20. //------------------------------------------------------
  21. //
  22. // Globals
  23. //
  24. //------------------------------------------------------
  25.  
  26.  
  27. ShimSerialGlobals*    gGlobals;
  28.  
  29.  
  30. //------------------------------------------------------
  31. //
  32. // Protos
  33. //
  34. //------------------------------------------------------
  35. static OSStatus SerialBoxValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc);
  36. static OSStatus serialBoxInitInterface(
  37.             UInt32                         interfaceNum, 
  38.             USBInterfaceDescriptor        *interfaceDesc, 
  39.             USBDeviceDescriptor            *deviceDesc, 
  40.             USBDeviceRef                 device);
  41. static OSStatus serialBoxInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc,
  42.                                     UInt32 busPowerAvailable);
  43. static OSStatus serialBoxFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  44. static OSStatus ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify);
  45. static OSStatus    serialBoxNotifyProc(UInt32     notification, void *pointer);
  46.  
  47.  
  48. //------------------------------------------------------
  49. //
  50. //    This is the driver description structure that the expert looks for first.
  51. //  If it's here, the information within is used to match the driver
  52. //  to the device whose descriptor was passed to the expert.
  53. //    Information in this block is also used by the expert when an
  54. //  entry is created in the Name Registry.
  55. //
  56. //------------------------------------------------------
  57. USBDriverDescription    TheUSBDriverDescription = 
  58. {
  59.     // Signature info
  60.     kTheUSBDriverDescriptionSignature,
  61.     kInitialUSBDriverDescriptor,
  62.     
  63.     // Device Info
  64. //    0x4C1, 0x3021,                            // vendor = USR 56K modem
  65.     0x565, 1,                                // vendor = Peracom USB to Serial Converter
  66. //    0x56c, 7,                                // vendor = e-Tek Labs/serial box
  67.     0,                                        // version of product = not device specific
  68.     0,                                        // protocol = not device specific
  69.     
  70.     // Interface Info    (* I don't think this would always be required...*)                
  71.     0,                                        // Configuration Value
  72.     0,                                        // Interface Number
  73.     0,                                        // Interface Class
  74.     0,                                         // Interface SubClass
  75.     0,                                        // Interface Protocol
  76.         
  77.     
  78.     // Driver Info
  79.     "\pSerialBox",                            // Driver name for Name Registry
  80.     0,                // Device Class  (from USBDeviceDefines.h)
  81.     0,                // Device Subclass 
  82.     0x0, 0x0, 0x20, 0x1,                    // version of driver = 0.0d1
  83.     
  84.     // Driver Loading Info
  85.     kUSBDoNotMatchGenericDevice                // Flags 
  86. };
  87.  
  88.     
  89. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  90. {
  91.     kClassDriverPluginVersion,            // Version of this structure
  92.     SerialBoxValidateHW,                // Hardware Validation Procedure
  93.     serialBoxInitialize,                // Initialization Procedure
  94.     serialBoxInitInterface,                // Interface Initialization Procedure
  95.     serialBoxFinalize,                    // Finalization Procedure
  96.     serialBoxNotifyProc,
  97. };
  98.  
  99. // Hardware Validation
  100. // Called upon load by Expert
  101. static OSStatus SerialBoxValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  102. {
  103.     device = 0;
  104.     desc = 0;
  105.     return (OSStatus)noErr;
  106. }
  107.  
  108.  
  109. // Initialization function
  110. // Called upon load by Expert
  111. static OSStatus serialBoxInitialize(USBDeviceRef device, USBDeviceDescriptorPtr deviceDesc,
  112.                                     UInt32 busPowerAvailable)
  113. {
  114. #pragma unused (busPowerAvailable)
  115.     gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
  116.     if (gGlobals == NULL)
  117.         goto bail;
  118.  
  119.     serialBoxEntry(device, deviceDesc);
  120.  
  121.     //    Install Device Control Entry for both the ".In" and ".Out functions that are
  122.     //    requied for a serial driver which is what we are.
  123.     if (noErr != InstallDriverControlEntries())
  124.     {
  125.         SysDebugStr("\pCan't install DCEs!");
  126.         goto bail;
  127.     }
  128.  
  129.     return (OSStatus)noErr;
  130.  
  131. bail:
  132.     if (gGlobals)
  133.         PoolDeallocate(gGlobals);
  134.     gGlobals = NULL;
  135.     
  136.     return (OSStatus)openErr;
  137. }
  138.  
  139. // hubDriverInitInterface function
  140. // Called to initialize driver for an individual interface - either by expert or
  141. // internally by driver
  142. static OSStatus serialBoxInitInterface(
  143.             UInt32                         interfaceNum, 
  144.             USBInterfaceDescriptor        *interfaceDesc, 
  145.             USBDeviceDescriptor            *deviceDesc, 
  146.             USBDeviceRef                 device)
  147. {
  148. #pragma unused (interfaceNum)
  149. #pragma unused (interfaceDesc)
  150.  
  151.     if (gGlobals == NULL)
  152.         gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
  153.  
  154.     if (gGlobals == NULL)
  155.         goto bail;
  156.  
  157.     serialBoxEntry(device, deviceDesc);
  158.  
  159.     //    Install Device Control Entry for both the ".In" and ".Out functions that are
  160.     //    requied for a serial driver which is what we are.
  161.     if (noErr != InstallDriverControlEntries())
  162.     {
  163.         SysDebugStr("\pCan't install DCEs!");
  164.         goto bail;
  165.     }
  166.  
  167.     return (OSStatus)noErr;
  168.  
  169. bail:
  170.     if (gGlobals)
  171.         PoolDeallocate(gGlobals);
  172.     gGlobals = NULL;
  173.     
  174.     return (OSStatus)openErr;
  175. }
  176.  
  177. // Termination function
  178. // Called by Expert when driver is being shut down
  179. static OSStatus serialBoxFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
  180. {
  181.     device = 0;
  182.     pDesc = 0;
  183.     
  184.     KillUSBIO();
  185.  
  186.     RemoveDriverControlEntries();
  187.     
  188.     return (OSStatus)noErr;
  189. }
  190.  
  191. static OSStatus ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
  192. {
  193.     pExpertNotify = 0;
  194. //    ExpertNotify(pExpertNotify);
  195.     return(noErr);
  196. }
  197.  
  198. static OSStatus    serialBoxNotifyProc(UInt32     notification, void *pointer)
  199. {
  200. #pragma unused (pointer)
  201.  
  202.     notification = 0;
  203.     return(noErr);
  204. }
  205.  
  206.